<%--
  Created by IntelliJ IDEA.
  User: ljh
  Date: 2024/10/29
  Time: 19:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored ="false" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>

<%@ include file="partials/_start.jsp" %>

<div class="content-wrapper" id="main">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-12 d-flex justify-content-between">
                    <h1>博客列表</h1>
                    <a href="${pageContext.request.contextPath}/admin-blog-add">创建新博客</a>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <!-- 添加搜索框 -->
                        <div class="card-header">
                            <form method="get" class="form-inline">
                                <div class="input-group" style="width: 300px;">
                                    <input type="text" name="search" class="form-control"
                                           placeholder="搜索博客标题..." value="${search}">
                                    <div class="input-group-append">
                                        <button type="submit" class="btn btn-default">
                                            <i class="fas fa-search"></i>
                                        </button>
                                        <c:if test="${not empty search}">
                                            <a href="${pageContext.request.contextPath}${pageContext.request.getAttribute('jakarta.servlet.forward.servlet_path')}"
                                               class="btn btn-default"
                                               title="清除搜索条件">
                                                <i class="fas fa-times"></i>
                                            </a>
                                        </c:if>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="card-body table-responsive p-0">
                            <table class="table table-hover text-nowrap">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Title</th>
                                    <th>Action</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach items="${blogs}" var="blog">
                                    <tr>
                                        <th>${blog.id}</th>
                                        <td><a href="${pageContext.request.contextPath}/blog-show?id=${blog.id}" target="_blank">${blog.title}</a></td>
                                        <td class="center">
                                            <a href="${pageContext.request.contextPath}/admin-blog-edit?id=${blog.id}" class="text-sm">
                                                <i class="fas fa-edit"></i>
                                                Edit
                                            </a>
                                            <a class="text-sm pl-3" href="${pageContext.request.contextPath}/admin-blog-delete?id=${blog.id}"
                                               onclick="return confirm('确定要删除这篇博客吗？此操作不可恢复！')">
                                                <i class="fas fa-trash"></i>
                                                Remove
                                            </a>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.card-body -->
                        <div class="card-footer clearfix">
                            <div class="row">
                                <div class="col-sm-12 col-md-5">
                                    <div class="dataTables_info" role="status" aria-live="polite">
                                        共 ${totalRecords} 条记录，当前第 ${currentPage}/${totalPages} 页
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-7">
                                    <div class="dataTables_paginate paging_simple_numbers">
                                        <ul class="pagination">
                                            <li class="paginate_button page-item previous ${currentPage == 1 ? 'disabled' : ''}">
                                                <a href="${pageContext.request.contextPath}${pageContext.request.getAttribute('jakarta.servlet.forward.servlet_path')}?page=${currentPage - 1}${search != null ? '&search='.concat(search) : ''}"
                                                   class="page-link">上一页</a>
                                            </li>

                                            <c:forEach begin="1" end="${totalPages}" var="i">
                                                <li class="paginate_button page-item ${currentPage == i ? 'active' : ''}">
                                                    <a href="${pageContext.request.contextPath}${pageContext.request.getAttribute('jakarta.servlet.forward.servlet_path')}?page=${i}${search != null ? '&search='.concat(search) : ''}"
                                                       class="page-link">${i}</a>
                                                </li>
                                            </c:forEach>

                                            <li class="paginate_button page-item next ${currentPage == totalPages ? 'disabled' : ''}">
                                                <a href="${pageContext.request.contextPath}${pageContext.request.getAttribute('jakarta.servlet.forward.servlet_path')}?page=${currentPage + 1}${search != null ? '&search='.concat(search) : ''}"
                                                   class="page-link">下一页</a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- /.card -->
                </div>
            </div>
        </div>
    </section>
</div>

<%@ include file="partials/_end.jsp" %>